"""Legacy entrypoint kept for compatibility.

Prefer running ``uvicorn backend.api.main:app --host 127.0.0.1 --port 8001``.
This module simply proxies to the canonical FastAPI application defined in
``backend.api.main`` so existing scripts keep working.
"""
from backend.api.main import app  # noqa: F401

import os

import uvicorn

from backend.common.config import config_manager


def main() -> None:
    server_config = config_manager.get_server_config()
    host = server_config.get("host", os.getenv("HOST", "127.0.0.1"))
    port = int(server_config.get("port", os.getenv("PORT", "8001")))
    reload = server_config.get("reload", os.getenv("DEBUG", "false").lower() == "true")
    workers = int(server_config.get("workers", os.getenv("WORKERS", "1")))
    log_level = server_config.get("log_level", os.getenv("LOG_LEVEL", "info"))
    
    uvicorn.run(
        "backend.api.main:app",
        host=host,
        port=port,
        reload=reload,
        workers=workers,
        log_level=log_level.lower(),
    )


if __name__ == "__main__":
    main()
